<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta top="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    body {
        margin: 10px;
    }
    .box{
        width: 100%;
        display: flex;

    }

    .title {
        line-height: 40px;
        font-weight: 700;
    }

    .list .item {
        display: flex;
        /* justify-content: space-between; */
        align-items: center;
        font-size: 12px;
        margin-bottom: 10px;

    }

    .list .item img {
        width: 100px;
        border-radius: 5px;
    }

    .list .item .middle .top {
        font-weight: 700;
        font-size: 16px;
        margin-bottom: 5px;
    }

    .list .item .middle .price {
        color: red;
        margin-bottom: 5px;
        font-weight: 700;
        font-size: 16px;


    }

    .list .item .pic2 {
        width: 15px;

    }

    .list .item .middle del {
        color: red;
        font-weight: 100;
        font-size: 12px;
        color: gray;


    }

    .list .item .middle .a {
        color: gray;
        margin: 5px 0;
    }

    .list .item .middle {
        width: 300px;
        height: 100px;
        margin: 0 20px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .right button {
        background-color: orangered;
        border-radius: 15px;
        border: 0;
        padding: 5px 15px;
        color: white;

    }

    .bottom {
        display: flex;
        justify-content: space-between;

    }

    .add {
        width: 80px;
        display: flex;
        justify-content: space-between;
        font-size: 16px;
        font-weight: 700;


    }

    .jian {
        width: 20px;
        height: 20px;
        border: 2px solid rgb(73, 178, 235);
        border-radius: 50%;
        box-sizing: border-box;
        text-align: center;
        line-height: 15px;
        color: rgb(73, 178, 235);
        display: block;
        cursor: pointer;

    }

    .jia {
        width: 20px;
        height: 20px;
        background-color: rgb(73, 178, 235);
        border-radius: 50%;
        text-align: center;
        color: white;
        line-height: 16px;
        display: block;
        cursor: pointer;
    }
    .qing{
        font-weight: 700;
        margin-left: 200px;
        line-height: 40px;
        cursor: pointer;

    }
    .heji{
        font-weight: 700;
        display: flex;

    }
    .zongshu{
        margin-left: 290px;
    }
    .zongjia{
        margin-left: 30px;
    }
</style>

<body>
    <div id="app">
        <div class="box">
            <div class="title">热门单品</div>
            <div class="qing" @click="delAll">清空</div>
        </div>
        <div class="list">
            <div class="item" v-for="(item,index) in tasklist" key="index">
                <div class="left">
                    <img v-bind:src="item.pic" alt="">
                </div>
                <div class="middle">
                    <div class="top"> {{item.top}} </div>
                    <div class="bottom">
                        <div class="price"> {{item.price}} <del> {{item.b}} </del></div>
                        <div class="add">
                            <div class="jian" @click="jian(item);del(item,index);zongshu();zongjia()">-</div>
                            <div class="num">{{item.status}}</div>
                            <div class="jia" @click="jia(item);zongshu();zongjia()">+</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="heji">
            <div class="zongshu">总数:{{num}}</div>
            <div class="zongjia">总价:￥{{total}}</div>
        </div>
    </div>

</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    //实例化Vue对象
    var v = new Vue({
        el: '#app',//el 表示Vue实例挂载的dom节点，id选择器
        data: {
            tasklist: [
                { id: 1, pic: './pic.png', top: '秋刀鱼/斤', price: '￥35.00', b: '￥35.00', status: 1 },
                { id: 2, pic: './pic.png', top: '鲜大带鱼/条', price: '￥45.00', b: '￥55.00', status: 1 },
                { id: 3, pic: './pic.png', top: '鲜活全母皮皮虾/斤', price: '￥35.00', b: '￥95.00', status: 1 },
            ],
            num: '3',
            total: '115'
        },//data 定义响应式数据，data的类型可以是对象，也可以是函数
        // data:function(){return{}} 两种写法
        computed: {},//定义计算属性
        watch: {},//定义数据监听
        methods: {
            //状态
            jia(item) {
                if (item.status < 5) {
                    item.status++
                }
            },
            jian(item) {
                if (item.status > 0) {
                    item.status--
                }
            },
            del(item,index){
                if(item.status==0){
                    console.log(item);
                    this.tasklist.splice(index,1)
                }
                
            },
            //总数
            zongshu(){
                var num1=0
                this.tasklist.forEach((item) => {
                    num1+=item.status
                });
                this.num=num1
            },
            // 总价
            zongjia(){
                var price1=0
                this.tasklist.forEach((item) => {
                    console.log(item.price.substring(1,item.price.length),item.status);
                    price1 += item.price.substring(1,item.price.length)*1 * item.status
                });
                this.total=price1
            },
            //一键清空
            delAll(){
                this.tasklist=[]
                this.num=0
                this.total=0
                
            }
        },//定义方法(函数)
    })

</script>